﻿using System;
using System.Drawing;
using System.Windows.Forms;
using Masterduner.SourceStudio.Practices.DevelopmentLibrary.Utilities.DataConfiguration.Generators;

namespace Masterduner.SourceStudio.Practices.DevelopmentLibrary.Utilities.DataConfiguration.Windows
{
    public partial class ErrorDialogWindow : Form
    {
        public ErrorDialogWindow()
        {
            InitializeComponent();

            this.InitializeControlsTheme();
        }

        #region InitializeControlsTheme
        /// <summary>
        /// 初始化控件的主题。
        /// </summary>
        private void InitializeControlsTheme()
        {
            this.SetFormBackgroundColor();
            this.SetOkButtonBackgroundColor();
            this.SetLinkLabelForeColor();
        }

        #region SetFormBackgroundColor
        /// <summary>
        /// 设置窗体的背景色。
        /// </summary>
        private void SetFormBackgroundColor()
        {
            this.BackColor = ColorTranslator.FromHtml("#16160E");
        }
        #endregion

        #region SetOkButtonBackgroundColor
        /// <summary>
        /// 设置确定按钮的背景色。
        /// </summary>
        private void SetOkButtonBackgroundColor()
        {
            this.btnOK.BackColor = ColorTranslator.FromHtml("#88CB7F");
        }
        #endregion

        #region SetLinkLabelForeColor
        /// <summary>
        /// 设置“复制”链接的前景色。
        /// </summary>
        private void SetLinkLabelForeColor()
        {
            this.btnCopyErrorMessage.ForeColor = ColorTranslator.FromHtml("#2B2B2B");
            this.btnCopyErrorMessage.LinkColor = ColorTranslator.FromHtml("#7D7D7D");
            this.btnCopyErrorMessage.ActiveLinkColor = ColorTranslator.FromHtml("#7D7D7D");
        }
        #endregion
        #endregion

        #region btnOK_Click
        private void btnOK_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
        #endregion

        #region btnCopyErrorMessage_LinkClicked
        private void btnCopyErrorMessage_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (!this.tbErrorMessage.Text.IsEmptyOrWriteSpaces())
                Clipboard.SetText(this.tbErrorMessage.Text, TextDataFormat.Text);
        }
        #endregion

        #region Show
        /// <summary>
        /// 显示异常对话框。
        /// </summary>
        /// <param name="exception"></param>
        /// <returns></returns>
        internal DialogResult Show(Exception exception)
        {
            this.tbErrorMessage.Text = new ExceptionMessageGenerator() { Exception = exception }.TransformText();
            return this.ShowDialog();
        }
        #endregion
    }
}
